package cc.fs.zhihuapp.ui.activity.demo;

import android.content.DialogInterface;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;
import cc.fs.zhihuapp.R;
import cc.fs.zhihuapp.ui.adapter.NormalAdapter;

/**
 * Created by fostion on 2015/9/1.
 */
public class ToolbarLayoutActivity extends AppCompatActivity {
    /**
     * 这种方式暂时有问题
     */

    //    RecyclerView recyclerView;
//    ImageView backdrop;
    @InjectView(R.id.toolbar)
    Toolbar toolbar;
    @InjectView(R.id.collapsing_toolbar)
    CollapsingToolbarLayout collapsingToolbar;
    @InjectView(R.id.title)
    TextView title;
    @InjectView(R.id.baseMsg)
    TextView baseMsg;
    @InjectView(R.id.introdution)
    TextView introdution;
    @InjectView(R.id.coordinatorLayout)
    CoordinatorLayout coordinatorLayout;
    @InjectView(R.id.poster)
    ImageView poster;
    @InjectView(R.id.chatBtn)
    TextView chatBtn;
    @InjectView(R.id.commentBtn)
    TextView commentBtn;
    @InjectView(R.id.dateBtn)
    TextView dateBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.acitivity_toolbar_layout);
        ButterKnife.inject(this);
        setUpView();
    }

    void setUpView() {
        toolbar = (Toolbar) findViewById(R.id.toolbar);
//        recyclerView = (RecyclerView)findViewById(R.id.recycler_view);
//        backdrop = (ImageView)findViewById(R.id.backdrop);
        coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinatorLayout);

//        toolbar.setTitle("电影");
//        toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
//        setSupportActionBar(toolbar);
//        ActionBar actionBar = getSupportActionBar();
//        if(actionBar != null){
//            actionBar.setDisplayHomeAsUpEnabled(true);
//            actionBar.setTitle("电影");
//        }

        final CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
        collapsingToolbar.setCollapsedTitleTextColor(Color.WHITE);
        collapsingToolbar.setExpandedTitleColor(Color.WHITE);
//        collapsingToolbar.setTitle("我的ScrollBar");

        ArrayList<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        list.add("5");
        list.add("6");
        list.add("7");
        list.add("8");
        list.add("9");
        list.add("10");

        NormalAdapter adapter = new NormalAdapter(list);

//        chatBtn.setSelected(true);
//        recyclerView.setLayoutManager(new LinearLayoutManager(this));
//        recyclerView.setAdapter(adapter);

//        backdrop.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showDialog();
//            }
//        });

        chatBtn.setOnClickListener(new MySelector());
        commentBtn.setOnClickListener(new MySelector());
        dateBtn.setOnClickListener(new MySelector());


    }

    void showDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(ToolbarLayoutActivity.this, R.style.MyAlertDialog);
        builder.setTitle("我是标题");
        builder.setMessage("这是我要显示的内容");
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        }).setNeutralButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        builder.create().show();
    }


    void showSnaciBar() {
        final Snackbar snackbar = Snackbar.make(coordinatorLayout, "Snack Bar", Snackbar.LENGTH_SHORT);
        snackbar.setAction("Dismiss", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                snackbar.dismiss();
            }
        });
        snackbar.show();
    }

    class MySelector implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            if(v.getId() == chatBtn.getId()){
                chatBtn.setSelected(true);
                commentBtn.setSelected(false);
                dateBtn.setSelected(false);
            }
            if(v.getId() == commentBtn.getId()){
                chatBtn.setSelected(false);
                commentBtn.setSelected(true);
                dateBtn.setSelected(false);
            }
            if(v.getId() == dateBtn.getId()){
                chatBtn.setSelected(false);
                commentBtn.setSelected(false);
                dateBtn.setSelected(true);
            }
        }
    }

}
